﻿@model string
<div class="current-location">
    <ul>
        <li class="left"><i class="glyphicon glyphicon-home"></i><a href="javascript:void(0)" onclick="location.href=location.href">上传附件管理</a></li>
        <li class="right"><a href="javascript:void(0)" onclick="LoadData()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a></li>
    </ul>
</div>
<div class="main">
    <div class="head-tab" id="head_tab">
        <ul class="navTabs">
            <li data-tab-params="tabName:'使用中',tabValue:'1',tabValueObjName:'#state'"></li>
            <li data-tab-params="tabName:'待使用',tabValue:'0',tabValueObjName:'#state'"></li>
            <li data-tab-params="tabName:'已失效',tabValue:'-1',tabValueObjName:'#state'"></li>
        </ul>
    </div>
    <ul class="clearfix">
        <li class="left">
            <div class="btn-group">
                <button type="button" class="btn btn-default btn-sm ui-selectInvert">反选</button>
                <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown" aria-expanded="false">
                    菜单
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu">
                    <li><a href="javascript:void(0)" class="ui-deleteMultiple" data-custom-params="url:'@Url.ActionUrl("Delete")?table=@ViewBag.Table',beforeExecute:'BeforeDelete',callBack:'LoadData'">删除</a></li>
                    <li class="divider"></li>
                    <li><a href="javascript:void(0)" class="ui-ajaxRequest" data-custom-params="url:'@Url.ActionUrl("Clear")',type:'post',confirmMsg:'是否确定清理？',successMsg:'已经提交到后台处理！'">清理失效附件</a></li>
                </ul>
            </div>
        </li>
        <li class="right form-group-sm form-inline">
            <input type="hidden" name="state" id="state" value="1" class="ui-queryString" />
            <input name="thedate" id="thedate" Maxlength="10" style="width:105px" placeholder="开始时间" class="laydate-icon form-control ui-queryString" onclick="laydate({istime:true,format:'YYYY-MM-DD'})">
            <input name="thedate" id="thedate" Maxlength="10" style="width:105px" placeholder="结束时间" class="laydate-icon form-control ui-queryString" onclick="laydate({istime:true,format:'YYYY-MM-DD'})">
            <select id="s_type" name="s_type" class="form-control form-control-xs ui-queryString ui-setName">
                <option value="username">按用户搜索</option>
                <option value="path">按文件名搜索</option>
            </select>
            <input type="text" id="username" name="username" placeholder="关键字" class="form-control ui-queryString ui-keyword" style="width:100px">
            <button type="button" class="btn btn-default btn-sm ui-queryString-search">确定</button>
        </li>
    </ul>
    <span class="help-block"></span>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered" id="tb_list">
        <thead>
            <tr>
                <td align="center" width="30px"><input type="checkbox" title="选择" class="ui-selectInvert" data-custom-params="isReverse:false"></td>
                <td align="center">文件信息</td>
                <td align="center">所属表</td>
                <td align="center">所属字段</td>
                <td align="center">数据Id</td>
                <td align="center">大小</td>
                <td align="center">时间</td>
                <td align="center">发布人</td>
            </tr>
        </thead>
        <tr class="item list-template-item" id="item_{id}" state="{state}">
            <td align="center" width="30px">
                <input type="checkbox" value="{id}" class="checked-item" />
                <input type="hidden" name="id" value="{id}" />
                <input type="hidden" name="guid" value="{guid}" />
            </td>

            <td align="left"><a class="filepath" href="{path}" target="_blank">{path}</a></td>
            <td align="center">{TableName}</td>
            <td align="center">{FieldName}</td>
            <td align="center">{detailId}</td>
            <td align="center">{size}kb</td>
            <td align="center">{thedate}</td>
            <td align="center">{username}</td>
        </tr>
    </table>
</div>

<script type="text/javascript">
    $(".navTabs").children().InitTab(function () { LoadData() }); //初始化选项卡，并设置回调函数为LoadData()

    function LoadData()
    {
        var ajaxUrl = "@Url.ActionUrl("PageListData")?table=@ViewBag.Table";
        var $tbList = $("#tb_list");
        $tbList.ListBind({url:ajaxUrl,callBack: "LoadedInit" });
    }

    function LoadedInit()
    {
        //var $lb_state = $(".lb_state");
        //$lb_state.each(function () {
        //    var $this = $(this);
        //    var thisHtml = $this.html();
        //    if (thisHtml == "-1") {
        //        $this.html("已删除")
        //    }
        //    else if (thisHtml == "0") {
        //        $this.html("未使用")
        //    }
        //    else if (thisHtml == "1") {
        //        $this.html("使用中").parent().parent().find(".ui-deleteSingle").attr("disabled", "disabled");
        //    }
        //});
      //$(".dropdown-hover").DropdownHover();
    }
    LoadData()

    function BeforeDelete(ids) {
        var arrIds = ids.split(",")
        for (i = 0; i < arrIds.length; i++) {
            if ($("#item_" + arrIds[i]).attr("state") != "-1") {
                Alert("对不起，只能删除已失效的附件！");
                return false;
            }
        }
        return true;
    }

</script>
